<?php
    define('CONFIG_FILE',true);
    include '../config.php';
    
    define('DB_FILE',true);
    require_once '../Tool/DB/SqlDBManager.class.php';

    session_start();
    if (empty($_SESSION["userType"])) {
        $url="../Index.php";
        include_once '../Tool/Common/Redirect.php';
        exit();
    }
    
    $NRIC = $_REQUEST['InsertNRIC'];
    $customerName = $_REQUEST['InsertCustomerName'];
    $citizenship = $_REQUEST['InsertCitizenship'];
    $beforeDeviation = intval($_REQUEST['InsertBeforeDeviation']);
    $afterDeviation = intval($_REQUEST['InsertAfterDeviation']);
    $dateOfBirth = $_REQUEST['InsertDateOfBirth'];
    $gender = $_REQUEST['InsertGender'];
    $centreId = intval($_REQUEST['InsertCentreName']);
    $daycare = $_REQUEST['InsertDaycare'];

    $sqlDBManager = new SqlDBManager();

    $sql = "INSERT INTO client (NRIC,CustomerName,Citizenship,BeforeDeviation,AfterDeviation, DateOfBirth,Gender,CentreId,Daycare) VALUES (?,?,?,?,?,?,?,?,?)";
	$parameters = array($NRIC,$customerName,$citizenship,$beforeDeviation,$afterDeviation,$dateOfBirth,$gender,$centreId,$daycare);
    $res = $sqlDBManager->execute_dml($sql,$parameters);

    //close connection
    $sqlDBManager->close_connect();
    
    if ($res>0){
        echo json_encode(array('success' => true));
    }else{
        echo json_encode(array('msg' => 'Create new client failed due to database error.'));
    }
    
    
?>